﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Boundary_FrmLogin : System.Web.UI.Page
{
    CtrlLogin ctrlLogin = new CtrlLogin();

    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies.Get("requmanaLogin");

        if (cookie != null)
        {
            Response.Redirect("FrmPrincipal.aspx");
        }
    }

    protected void btnSignIn_Click(object sender, EventArgs e)
    {

        string[] userData = ctrlLogin.userExists(txtUsername.Text, txtPassword.Text);

        if (userData != null)
        {
            HttpCookie cookie = new HttpCookie("requmanaLogin");
            cookie.Values.Add("username", userData[0]);
            cookie.Values.Add("firstName", userData[1]);
            cookie.Values.Add("lastName", userData[2]);
            cookie.Values.Add("profile", userData[3]);
            cookie.Values.Add("role", userData[4]);
            cookie.Values.Add("id", userData[5]);
            cookie.Values.Add("color", "verde");
            Response.Cookies.Add(cookie);

            //HttpCookieEncryption.Encrypt(this.Context, "requmanaLogin");

            Response.Redirect("FrmPrincipal.aspx");
        }
        else
        {
            ctlMessage1.showMessage("error", "Usuario y/o contraseña incorrecto(s).");
        }

        

    }
}
